package com.ruoyi.project.common.feedback.controller;

import java.util.List;

import com.ruoyi.project.lesson.lesson.domain.Lesson;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.common.feedback.domain.DictFeedback;
import com.ruoyi.project.common.feedback.service.IDictFeedbackService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 意见反馈Controller
 * 
 * @author shixiangwen
 * @date 2022-03-03
 */
@Controller
@RequestMapping("/common/feedback")
public class DictFeedbackController extends BaseController
{
    private String prefix = "common/feedback";

    @Autowired
    private IDictFeedbackService dictFeedbackService;

    @RequiresPermissions("common:feedback:view")
    @GetMapping()
    public String feedback()
    {
        return prefix + "/feedback";
    }

    /**
     * 查询意见反馈列表
     */
    @RequiresPermissions("common:feedback:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DictFeedback dictFeedback)
    {
        startPage();
        List<DictFeedback> list = dictFeedbackService.selectDictFeedbackList(dictFeedback);
        return getDataTable(list);
    }

    /**
     * 导出意见反馈列表
     */
    @RequiresPermissions("common:feedback:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DictFeedback dictFeedback)
    {
        List<DictFeedback> list = dictFeedbackService.selectDictFeedbackList(dictFeedback);
        ExcelUtil<DictFeedback> util = new ExcelUtil<DictFeedback>(DictFeedback.class);
        return util.exportExcel(list, "feedback");
    }

    /**
     * 新增意见反馈
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存意见反馈
     */
    @RequiresPermissions("common:feedback:add")
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DictFeedback dictFeedback)
    {
        return toAjax(dictFeedbackService.insertDictFeedback(dictFeedback));
    }

    /**
     * 修改意见反馈
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DictFeedback dictFeedback = dictFeedbackService.selectDictFeedbackById(id);
        mmap.put("dictFeedback", dictFeedback);
        return prefix + "/edit";
    }

    @RequiresPermissions("common:feedback:edit")
    @Log(title = "意见反馈", businessType = BusinessType.GRANT)
    @PostMapping("/updateStatus/{id}")
    @ResponseBody
    public AjaxResult updateStatus(@PathVariable("id") Long id, Integer status) {

        DictFeedback dictFeedback = dictFeedbackService.selectDictFeedbackById(id);
        dictFeedback.setStatus(status);

        return toAjax(dictFeedbackService.updateDictFeedback(dictFeedback));
    }


    /**
     * 修改保存意见反馈
     */
    @RequiresPermissions("common:feedback:edit")
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DictFeedback dictFeedback)
    {
        return toAjax(dictFeedbackService.updateDictFeedback(dictFeedback));
    }

    /**
     * 删除意见反馈
     */
    @RequiresPermissions("common:feedback:remove")
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dictFeedbackService.deleteDictFeedbackByIds(ids));
    }
}
